import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: '',
    tokenHead: '',
    viewKey: 0
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    },
    setTokenHead(state, tokenHead) {
      state.tokenHead = tokenHead
    },
    addKey(state) {
      state.viewKey += 1
    },
    clearLogin(state) {
      state.token = ''
      state.tokenHead = ''
    }
  },
  actions: {
    asyncSetToken(state, token) {
      state.commit('setToken', token)
    },
    asyncSetTokenHead(state, tokenHead) {
      state.commit('setTokenHead', tokenHead)
    }

  }
})
